package com.mapper;

import com.pojo.Cart;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface CartMapper {
    @Select("SELECT * FROM cart WHERE user_id = #{userId}")
    List<Cart> findByUserId(Long userId);

    @Select("SELECT * FROM cart WHERE user_id = #{userId} AND product_id = #{productId}")
    Cart findByUserIdAndProductId(@Param("userId") Long userId, @Param("productId") Long productId);

    @Insert("INSERT INTO cart(user_id, product_id, quantity, selected) VALUES(#{userId}, #{productId}, #{quantity}, #{selected})")
    void insert(Cart cart);

    @Update("UPDATE cart SET quantity = #{quantity}, selected = #{selected} WHERE id = #{id}")
    void update(Cart cart);

    @Delete("DELETE FROM cart WHERE user_id = #{userId} AND product_id = #{productId}")
    void deleteByUserIdAndProductId(@Param("userId") Long userId, @Param("productId") Long productId);
}
